<script setup lang="ts">
import {ElMessage,} from 'element-plus';

const beforeUpload=(file:any)=>{
  const isExcel = /\.(xlsx|xls)$/i.test(file.name)
  const isLt10M = file.size / 1024 / 1024 < 10

  if (!isExcel) {
    ElMessage.error('只能上传Excel文件!')
    return false
  }
  if (!isLt10M) {
    ElMessage.error('文件大小不能超过10MB!')
    return false
  }
  return true
}
</script>

<template>
  <el-upload
      class="upload-demo"
      drag
      accept=".xlsx"
      limit="1"
      action="https://jsonplaceholder.typicode.com/posts/"
      :before-upload="beforeUpload"
      >
    <i class="el-icon-upload"></i>
    <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
    <div class="el-upload__tip" slot="tip">只能上传xlsx文件</div>
  </el-upload>
</template>
<style scoped>

</style>